
package cz.muni.fi.pa165.rentalofconstructionmachinery.dto.converters;

import cz.muni.fi.pa165.rentalofconstructionmachinery.dto.CustomerDTO;
import cz.muni.fi.pa165.rentalofconstructionmachinery.entity.Customer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Zuzana Krejcova
 */
public class CustomerDTOConverter {

    
    public static Customer dtoToEntity(CustomerDTO dto) {
        
        if(null == dto) return null;
        
        Customer customer = new Customer();
        customer.setId(dto.getId());
        customer.setName(dto.getName());
        customer.setType(dto.getType());
        customer.setUsername(dto.getUsername());
        customer.setPassword(dto.getPassword());
        customer.setAccessLevel(dto.getAccessLevel());
        return customer;
    }

    public static CustomerDTO entityToDTO(Customer customer) {
        if(null == customer) return null;
        else return new CustomerDTO(customer.getId(), customer.getName(), customer.getType(),
                customer.getUsername(), customer.getPassword(), customer.getAccessLevel());
    }

    public static List<CustomerDTO> entityToDTOList(List<Customer> list) {
        List<CustomerDTO> dtoList = new ArrayList<>(list.size());
        for (Customer customer : list) {
            dtoList.add(entityToDTO(customer));
        }
        return dtoList;
    }
}
